<template>
  <div id='userLayout' :class="['user-layout-wrapper', device]">


    <div id='container33' class='container'>
      <div class='top'>
        <div class='header'>
          <a>

<!--            <img src='~@/assets/nyncb_logo_1.png' class='logo' alt='logo'>-->
            <span class='title'>云南省数字冷库管理系统</span>
          </a>
        </div>
<!--        <div class='desc'>
          采后处理系统
        </div>-->
      </div>

      <route-view></route-view>

      <div class='footer'>

        <div class='links'>
          Copyright ©2023 云南省农业农村厅
        </div>
        <div class='links'>
          技术支持 云南云天化现代农业发展有限公司
        </div>

<!--        <div class='links'>
          网站备案号 <a href='https://beian.miit.gov.cn/#/Integrated/index' style='color: #00c5fd'>滇ICP备2022005134号-1</a>
        </div>-->
      </div>
    </div>
    <canvas id='container3214234' style='height: 100%;height: 100%;    background: #d9f5ce5c;position: fixed; top: 0px; left: 0px;    z-index: -1;    opacity: 0.5;'>

    </canvas>
  </div>
</template>

<script>
import RouteView from '@/components/layouts/RouteView'
import { mixinDevice } from '@/utils/mixin.js'

export default {
  name: 'UserLayout',
  components: { RouteView },
  mixins: [mixinDevice],
  data() {
    return {}
  },
  mounted() {
    document.body.classList.add('userLayout')
  },
  beforeDestroy() {
    document.body.classList.remove('userLayout')
  },
  created() {
    // this.getCanvasNew2()

    let that = this
    setTimeout(function() {
      that.getCanvasNew()
    }, 1500)
  },
  methods: {
    getCanvasNew() {
      //              var canvas = document.querySelector('myCanvas'),
      var canvas = document.getElementById('container3214234')
      canvas.width = document.documentElement.clientWidth || document.body.clientWidth
      canvas.height = document.documentElement.clientHeight || document.body.clientHeight
      var ctx = canvas.getContext('2d')

      ctx.lineWidth = .3
      ctx.strokeStyle = (new Color(150)).style

      var mousePosition = {
        x: 30 * canvas.width / 100,
        y: 30 * canvas.height / 100
      }

      var dots = {
        nb: 250,
        distance: 100,
        d_radius: 150,
        array: []
      }

      function colorValue(min) {
        return Math.floor(Math.random() * 255 + min)
      }

      function createColorStyle(r, g, b) {
        return 'rgba(' + r + ',' + g + ',' + b + ', 0.8)'
      }

      function mixComponents(comp1, weight1, comp2, weight2) {
        return (comp1 * weight1 + comp2 * weight2) / (weight1 + weight2)
      }

      function averageColorStyles(dot1, dot2) {
        var color1 = dot1.color,
          color2 = dot2.color

        var r = mixComponents(color1.r, dot1.radius, color2.r, dot2.radius),
          g = mixComponents(color1.g, dot1.radius, color2.g, dot2.radius),
          b = mixComponents(color1.b, dot1.radius, color2.b, dot2.radius)
        return createColorStyle(Math.floor(r), Math.floor(g), Math.floor(b))
      }

      function Color(min) {
        min = min || 0
        this.r = colorValue(min)
        this.g = colorValue(min)
        this.b = colorValue(min)
        this.style = createColorStyle(this.r, this.g, this.b)
      }

      function Dot() {
        this.x = Math.random() * canvas.width
        this.y = Math.random() * canvas.height

        this.vx = -.5 + Math.random()
        this.vy = -.5 + Math.random()

        this.radius = Math.random() * 2

        this.color = new Color()
      }

      Dot.prototype = {
        draw: function() {
          ctx.beginPath()
          ctx.fillStyle = this.color.style
          ctx.arc(this.x, this.y, this.radius, 0, Math.PI, false)
          ctx.fill()
        }
      }

      function createDots() {
        for (var i = 0; i < dots.nb; i++) {
          dots.array.push(new Dot())
        }
      }

      function moveDots() {
        for (var i = 0; i < dots.nb; i++) {

          var dot = dots.array[i]

          if (dot.y < 0 || dot.y > canvas.height) {
            dot.vx = dot.vx
            dot.vy = -dot.vy
          } else if (dot.x < 0 || dot.x > canvas.width) {
            dot.vx = -dot.vx
            dot.vy = dot.vy
          }
          dot.x += dot.vx
          dot.y += dot.vy
        }
      }

      function connectDots() {
        for (var i = 0; i < dots.nb; i++) {
          for (var j = 0; j < dots.nb; j++) {
            var i_dot = dots.array[i]
            var j_dot = dots.array[j]

            if ((i_dot.x - j_dot.x) < dots.distance && (i_dot.y - j_dot.y) < dots.distance && (i_dot.x - j_dot.x) > -dots.distance && (i_dot.y - j_dot.y) > -dots.distance) {
              if ((i_dot.x - mousePosition.x) < dots.d_radius && (i_dot.y - mousePosition.y) < dots.d_radius && (i_dot.x - mousePosition.x) > -dots.d_radius && (i_dot.y - mousePosition.y) > -dots.d_radius) {
                ctx.beginPath()
                ctx.strokeStyle = averageColorStyles(i_dot, j_dot)
                ctx.moveTo(i_dot.x, i_dot.y)
                ctx.lineTo(j_dot.x, j_dot.y)
                ctx.stroke()
                ctx.closePath()
              }
            }
          }
        }
      }

      function drawDots() {
        for (var i = 0; i < dots.nb; i++) {
          var dot = dots.array[i]
          dot.draw()
        }
      }

      function animateDots() {
        ctx.clearRect(0, 0, canvas.width, canvas.height)
        moveDots()
        connectDots()
        drawDots()

        requestAnimationFrame(animateDots)
      }

      canvas.onmousemove = function(e) {
        mousePosition.x = e.pageX
        mousePosition.y = e.pageY
      }
      canvas.mouseleave = function(e) {
        mousePosition.x = canvas.width / 2
        mousePosition.y = canvas.height / 2
      }
      createDots()
      requestAnimationFrame(animateDots)

    }


  }


}
</script>

<style lang='less' scoped>
#userLayout.user-layout-wrapper {
  height: 100%;

  &.mobile {
    .container {
      .main {
        max-width: 368px;
        width: 98%;
      }
    }
  }

  .container {
    width: 100%;
    min-height: 100%;
    //background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
    //background: #f0f2f5 url(~@/assets/bg.jpg) no-repeat 50%;
    background-size: 100%;
    padding: 110px 0 144px;
    position: relative;

    a {
      text-decoration: none;
    }

    .top {
      text-align: center;

      .header {
        height: 44px;
        line-height: 44px;

        .badge {
          position: absolute;
          display: inline-block;
          line-height: 1;
          vertical-align: middle;
          margin-left: -12px;
          margin-top: -10px;
          opacity: 0.8;
        }

        .logo {
          height: 44px;
          vertical-align: top;
          margin-right: 16px;
          border-style: none;
        }

        .title {
          font-size: 33px;
          color: rgba(0, 0, 0, .85);
          font-family: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
          font-weight: 600;
          position: relative;
          top: 2px;
        }
      }

      .desc {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
        margin-top: 12px;
        margin-bottom: 40px;
      }
    }

    .main {
      min-width: 260px;
      width: 368px;
      margin: 0 auto;
    }

    .footer {
      position: absolute;
      width: 100%;
      bottom: 0;
      padding: 0 16px;
      margin: 48px 0 24px;
      text-align: center;

      .links {
        margin-bottom: 8px;
        font-size: 14px;

        a {
          color: rgba(0, 0, 0, 0.45);
          transition: all 0.3s;

          &:not(:last-child) {
            margin-right: 40px;
          }
        }
      }

      .copyright {
        color: rgba(0, 0, 0, 0.45);
        font-size: 14px;
      }
    }
  }
}
</style>